<?php
/**
 * @Author:         zk
 * @DateTime:       18-6-5 上午10:52
 * @Description:    冲洗 anhui_data 库中 supply_brand "耗材品牌" 中的 品牌首字母
 */
$api_service_path = __DIR__ . "/../../../api/";
ob_start();
require_once($api_service_path . "public/index.php");
ob_end_clean();
set_time_limit(0);
//DB::connection()->disableQueryLog();      //关闭日志


    $supply_brand = DataSupplyBrand::select('id', 'brand_name')->orderBy('id');
    $supply_brand->chunk(500, function($brand){
        foreach ($brand as $v) {
            $pin_yin = Pinyin::getShortPinyin($v->brand_name);
            $first = strtoupper($pin_yin[0]);
            if(preg_match('/^[a-zA-Z]+$/', $first)){
                $v->initial = $first;
                $res = $v->save();
                if(!$res){
                    Log::info('id 为 '.$v->id.' 品牌名称为 '.$v->brand_name." 首字母添加失败");
                    echo 'id: '.$v->id.', brand_name: '.$v->brand_name." first letter error \n";
                }
            }else{
                Log::info('id 为 '.$v->id.' 品牌名称为 '.$v->brand_name." 首字母添加失败");
                echo 'id: '.$v->id.', brand_name: '.$v->brand_name." first letter error \n";
            }
        }
    });
        

Log::info("supply_brand ok"); 
echo "supply_brand ok";